package com.spa.common.utils;

import java.io.IOException;

import com.fasterxml.jackson.core.JsonGenerator;
import com.fasterxml.jackson.databind.JsonSerializer;
import com.fasterxml.jackson.databind.SerializerProvider;

// 在实体类的long类型属性上加上注解：@JsonSerialize(using =LongToStringSerializer.class)
// Long类型数据(eg：id)传到前台会超出JS精确整形范围，因此转化为String传到前台
public class LongToStringUtil extends JsonSerializer<Long> {
 
    @Override
    public void serialize(Long value, JsonGenerator gen, SerializerProvider serializers) throws IOException {
        if(null!=value) {
            gen.writeString(String.valueOf(value));
        }
    }
}